﻿


using System.Data;

namespace Orid.Management.Statistics.Tools.Decomposition.DecompositionDB
{
    using System;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;
    using SqlHelper = Orid.Data.SqlServer.SqlHelper;

    class DataProvider
    {
        #region 构造函数

        string connectString = string.Empty;

        public DataProvider()
        {
            //分解数据库地址
            connectString = Config.Setting.SettingInstance.DBAddress_Decomposition;
        }
        #endregion

        #region StaticState Table

        public   void StaticInsert(Guid OrderID,string OrderState,Guid StaticID,DateTime StarDateTime,string memo)
        {
            StringBuilder StaticSql = new StringBuilder();


            StaticSql.Append(" INSERT INTO [StaticState]");
            StaticSql.Append(" (");
            StaticSql.Append(" [OrderID],[OrderState],[StaticID],[StaticDateTime],[memo]");
            StaticSql.Append(" )");
            StaticSql.Append(" VALUES");
            StaticSql.Append(" (");
            StaticSql.Append("  @OrderID");
            StaticSql.Append(" ,@OrderState");
            StaticSql.Append(" ,@StaticID");
            StaticSql.Append(" ,@StarDateTime");
            StaticSql.Append(" ,@memo");
            StaticSql.Append(" )");


              System.Data.SqlClient.SqlParameter[] SqlParameter;
              SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
             new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
             new System.Data.SqlClient.SqlParameter("@OrderState",OrderState),
             new System.Data.SqlClient.SqlParameter("@StaticID",StaticID),
             new System.Data.SqlClient.SqlParameter("@StarDateTime",StarDateTime),
             new System.Data.SqlClient.SqlParameter("@memo",memo),

            };


            ExecCommand(StaticSql.ToString(),SqlParameter);

        }

        public   void StaticUpdate(Guid StaticID, DateTime FinishDateTime)
        {
            StringBuilder StaticSql = new StringBuilder();

            StaticSql.Append(" UPDATE [StaticState]");
            StaticSql.Append(" SET");
            StaticSql.Append(" [FinishDateTime] = ");
            StaticSql.Append(" @FinishDateTime");
            StaticSql.Append(" WHERE");
            StaticSql.Append(" [StaticID] =");
            StaticSql.Append(" @StaticID ");

               System.Data.SqlClient.SqlParameter[] SqlParameter;
               SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
             new System.Data.SqlClient.SqlParameter("@FinishDateTime",FinishDateTime), 
             new System.Data.SqlClient.SqlParameter("@StaticID",StaticID),
            };

               
            ExecCommand(StaticSql.ToString(), SqlParameter);

        }

        public   Logic.OrderState GetOrderState(Guid StaticID)
        {
            StringBuilder StaticSql = new StringBuilder();

            StaticSql.Append(" SELECT TOP 1 [OrderState]");
            StaticSql.Append(" FROM  [StaticState]");
            StaticSql.Append(" WHERE [OrderID] =");
            StaticSql.Append(" '" + StaticID + "'");
            StaticSql.Append(" ORDER BY StaticDateTime DESC");

            try
            {
                
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {
                    conn.Open();


                    
                    object result = SqlHelper.ExecuteScalar(conn, System.Data.CommandType.Text, StaticSql.ToString());
                    string orderState;
                    if (result == null)
                        {
                            orderState = "UnFinished";

                        }
                        else
                        {
                            orderState = result as string;
                        }
                   

                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();

                    if (orderState == Logic.OrderState.Finished.ToString())
                    {
                        return Orid.Management.Statistics.Tools.Decomposition.Logic.OrderState.Finished;
                    }
                    return Orid.Management.Statistics.Tools.Decomposition.Logic.OrderState.UnFinished;
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw (new Exception(ex.Message));
            }
           

        }

        public DateTime? GetLastDecompositeTime(Guid StaticID,string Address)
        {
            StringBuilder StaticSql = new StringBuilder();

            StaticSql.Append(" SELECT TOP 1 [FinishDatetime]");
            StaticSql.Append(" FROM  [StaticState]");
            StaticSql.Append(" WHERE [OrderID] =@OrderID ");
            StaticSql.Append(" AND [Memo] =@Address ");
            StaticSql.Append(" ORDER BY StaticDateTime DESC");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
                               {
                                   new System.Data.SqlClient.SqlParameter("@OrderID", StaticID),
                                   new System.Data.SqlClient.SqlParameter("@Address", Address),
                               };



            try
            {
                DateTime?  StaticDateTime;
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {
                    conn.Open();


                   // StaticDateTime = SqlHelper.ExecuteScalar(conn, System.Data.CommandType.Text, StaticSql.ToString()) as DateTime?;

                    StaticDateTime =  SqlHelper.ExecuteScalar(conn, CommandType.Text, StaticSql.ToString(), SqlParameter) as DateTime?;

                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();
 

                }
                return StaticDateTime;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw (new Exception(ex.Message));
            }


        }

        #endregion

        #region Order

        public void OrderInsert(
            Guid OrderID, int MatterID, string MatterName, double DataCount, DateTime? DeliverDate,
            DateTime? OrderDeliveryDateTime, DateTime? StarDateTime, DateTime? FinishDateTime,
            DateTime? OrderDateTime, DateTime? CreateDateTime, double MTDuration, double MTPropagationTime,
            double TrimerDuration, double TrimerPropagationTime,
            double OCRDuration, double OCRPropagationTime,
            double ΑDuration, double ΑPropagationTime,
            double βDuration, double βPropagationTime, double ADuration, double APropagationTime,
            double BDuration, double BPropagationTime, double DDuration, double DPropagationTime,
            double EDuration, double EPropagationTime, double JudgeJobCount, double ABJobCount,
            double DJobCount, double EJobCount, Guid StaticID
            , double MachineDistinguishDuration, double MachineDistinguishPropagationTime
            , double ManualDistinguishDuration, double ManualDistinguishPropagationTime
            , string UserOrder
            ,double AImageCount,        double BImageCount,             double DImageCount,             double EImageCount
            ,double TrimerJobCount     ,double TrimerImageCount,        double JudegADuration,          double JudegAPropagationTime
            , double JudegBDuration, double JudegBPropagationTime,      double JudageAJobCount,              double JudageBJobCount
            , double JudgeAImageCount
            ,double JudgeBImageCount,   double FJobCount,               double FDuration                ,double FPropagationTime
            ,double FImageCount,        double GJobCount,               double GDuration,               double GPropagationTime
            , double GImageCount,       DateTime? OrderCancelDateTime,  string OrderComment,            string CustomerInformation

            )
        {
            StringBuilder orderSql = new StringBuilder();

            #region orderSql
            orderSql.Append(" INSERT INTO [Orders]");
            orderSql.Append(" (");
            orderSql.Append(" [OrderID]");
            orderSql.Append(" ,[MatterID]");
            orderSql.Append(" ,[MatterName]");
            orderSql.Append(" ,[DataCount]");
            orderSql.Append(" ,[DeliverDate]");
            orderSql.Append(" ,[OrderDeliveryDateTime]");
            orderSql.Append(" ,[StartDateTime] ");
            orderSql.Append(" ,[FinishDateTime] ");
            orderSql.Append(" ,[OrderDateTime] ");
            orderSql.Append(" ,[CreateDateTime] ");
            orderSql.Append(" ,[MTDuration] ");
            orderSql.Append(" ,[MTPropagationTime]");
            orderSql.Append(" ,[TrimerDuration] ");
            orderSql.Append(" ,[TrimerPropagationTime]");
            orderSql.Append(" ,[OCRDuration] ");
            orderSql.Append(" ,[OCRPropagationTime]");
            orderSql.Append(" ,[αDuration] ");
            orderSql.Append(" ,[αPropagationTime]");
            orderSql.Append(" ,[βDuration] ");
            orderSql.Append(" ,[βPropagationTime]");
            orderSql.Append(" ,[ADuration] ");
            orderSql.Append(" ,[APropagationTime]");
            orderSql.Append(" ,[BDuration] ");
            orderSql.Append(" ,[BPropagationTime]");
            orderSql.Append(" ,[DDuration] ");
            orderSql.Append(" ,[DPropagationTime]");
            orderSql.Append(" ,[EDuration] ");
            orderSql.Append(" ,[EPropagationTime]");
            orderSql.Append(" ,[JudgeJobCount] ");
            orderSql.Append(" ,[ABJobCount]");
            orderSql.Append(" ,[DJobCount]");
            orderSql.Append(" ,[EJobCount]");
            orderSql.Append(" ,[StaticID] ");
            orderSql.Append(" ,[MachineDistinguishDuration]");
            orderSql.Append(" ,[MachineDistinguishPropagationTime]");
            orderSql.Append(" ,[ManualDistinguishDuration]");
            orderSql.Append(" ,[ManualDistinguishPropagationTime]");
            orderSql.Append(" ,[UserOrder]");
            orderSql.Append(" ,[AImageCount]");
            orderSql.Append(" ,[BImageCount]");
            orderSql.Append(" ,[DImageCount]");
            orderSql.Append(" ,[EImageCount]");
            orderSql.Append(" ,[TrimerJobCount]");
            orderSql.Append(" ,[TrimerImageCount]");
            orderSql.Append(" ,[JudegADuration]");
            orderSql.Append(" ,[JudegAPropagationTime]");
            orderSql.Append(" ,[JudegBDuration]");
            orderSql.Append(" ,[JudegBPropagationTime]");
            orderSql.Append(" ,[JudageAJobCount]");
            orderSql.Append(" ,[JudageBJobCount]");
            orderSql.Append(" ,[JudgeAImageCount]");
            orderSql.Append(" ,[JudgeBImageCount]");
            orderSql.Append(" ,[FJobCount]");
            orderSql.Append(" ,[FDuration]");
            orderSql.Append(" ,[FPropagationTime]");
            orderSql.Append(" ,[FImageCount]");
            orderSql.Append(" ,[GJobCount]");
            orderSql.Append(" ,[GDuration]");
            orderSql.Append(" ,[GPropagationTime]");
            orderSql.Append(" ,[GImageCount]");
            orderSql.Append(" ,[OrderComment]");
            orderSql.Append(", [OrderCancelDateTime]");
            orderSql.Append(" ,[CustomerInformation]");
            orderSql.Append(" ) ");
            orderSql.Append(" VALUES ");
            orderSql.Append(" ( ");
            orderSql.Append("  @OrderID");
            orderSql.Append(" ,@MatterID");
            orderSql.Append(" ,@MatterName");
            orderSql.Append(" ,@DataCount");
            orderSql.Append(" ,@DeliverDate");
            orderSql.Append(" ,@OrderDeliveryDateTime");
            orderSql.Append(" ,@StartDateTime ");
            orderSql.Append(" ,@FinishDateTime ");
            orderSql.Append(" ,@OrderDateTime ");
            orderSql.Append(" ,@CreateDateTime ");
            orderSql.Append(" ,@MTDuration ");
            orderSql.Append(" ,@MTPropagationTime");
            orderSql.Append(" ,@TrimerDuration ");
            orderSql.Append(" ,@TrimerPropagationTime");
            orderSql.Append(" ,@OCRDuration ");
            orderSql.Append(" ,@OCRPropagationTime");
            orderSql.Append(" ,@αDuration ");
            orderSql.Append(" ,@αPropagationTime");
            orderSql.Append(" ,@βDuration ");
            orderSql.Append(" ,@βPropagationTime");
            orderSql.Append(" ,@ADuration ");
            orderSql.Append(" ,@APropagationTime");
            orderSql.Append(" ,@BDuration ");
            orderSql.Append(" ,@BPropagationTime");
            orderSql.Append(" ,@DDuration ");
            orderSql.Append(" ,@DPropagationTime");
            orderSql.Append(" ,@EDuration ");
            orderSql.Append(" ,@EPropagationTime");
            orderSql.Append(" ,@JudgeJobCount ");
            orderSql.Append(" ,@ABJobCount");
            orderSql.Append(" ,@DJobCount");
            orderSql.Append(" ,@EJobCount");
            orderSql.Append(" ,@StaticID ");
            orderSql.Append(" ,@MachineDistinguishDuration");
            orderSql.Append(" ,@MachineDistinguishPropagationTime");
            orderSql.Append(" ,@ManualDistinguishDuration");
            orderSql.Append(" ,@ManualDistinguishPropagationTime");
            orderSql.Append(" ,@UserOrder");
            orderSql.Append(" ,@AImageCount");
            orderSql.Append(" ,@BImageCount");
            orderSql.Append(" ,@DImageCount");
            orderSql.Append(" ,@EImageCount");
            orderSql.Append(" ,@TrimerJobCount");
            orderSql.Append(" ,@TrimerImageCount");
            orderSql.Append(" ,@JudegADuration");
            orderSql.Append(" ,@JudegAPropagationTime");
            orderSql.Append(" ,@JudegBDuration");
            orderSql.Append(" ,@JudegBPropagationTime");
            orderSql.Append(" ,@JudageAJobCount");
            orderSql.Append(" ,@JudageBJobCount");
            orderSql.Append(" ,@JudgeAImageCount");
            orderSql.Append(" ,@JudgeBImageCount");
            orderSql.Append(" ,@FJobCount");
            orderSql.Append(" ,@FDuration");
            orderSql.Append(" ,@FPropagationTime");
            orderSql.Append(" ,@FImageCount");
            orderSql.Append(" ,@GJobCount");
            orderSql.Append(" ,@GDuration");
            orderSql.Append(" ,@GPropagationTime");
            orderSql.Append(" ,@GImageCount");
            orderSql.Append(" ,@OrderComment");
            orderSql.Append(" ,@OrderCancelDateTime");
            orderSql.Append(" ,@CustomerInformation");
            orderSql.Append(")");

            #endregion
            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                new System.Data.SqlClient.SqlParameter("@MatterID",MatterID),
                new System.Data.SqlClient.SqlParameter("@MatterName",MatterName),
                new System.Data.SqlClient.SqlParameter("@DataCount",DataCount),
                new System.Data.SqlClient.SqlParameter("@DeliverDate",DeliverDate),
                new System.Data.SqlClient.SqlParameter("@OrderDeliveryDateTime",OrderDeliveryDateTime),
                new System.Data.SqlClient.SqlParameter("@StartDateTime",StarDateTime),
                new System.Data.SqlClient.SqlParameter("@FinishDateTime",FinishDateTime),
                new System.Data.SqlClient.SqlParameter("@OrderDateTime",OrderDateTime),
                new System.Data.SqlClient.SqlParameter("@CreateDateTime",CreateDateTime),
                new System.Data.SqlClient.SqlParameter("@MTDuration",MTDuration),
                new System.Data.SqlClient.SqlParameter("@MTPropagationTime",MTPropagationTime),
                new System.Data.SqlClient.SqlParameter("@TrimerDuration",TrimerDuration),
                new System.Data.SqlClient.SqlParameter("@TrimerPropagationTime",TrimerPropagationTime),
                new System.Data.SqlClient.SqlParameter("@OCRDuration",OCRDuration),
                new System.Data.SqlClient.SqlParameter("@OCRPropagationTime",OCRPropagationTime),
                new System.Data.SqlClient.SqlParameter("@αDuration",ΑDuration),
                new System.Data.SqlClient.SqlParameter("@αPropagationTime",ΑPropagationTime),
                new System.Data.SqlClient.SqlParameter("@βDuration",βDuration),
                new System.Data.SqlClient.SqlParameter("@βPropagationTime",βPropagationTime),
                new System.Data.SqlClient.SqlParameter("@ADuration",ADuration),
                new System.Data.SqlClient.SqlParameter("@APropagationTime",APropagationTime),
                new System.Data.SqlClient.SqlParameter("@BDuration",BDuration),
                new System.Data.SqlClient.SqlParameter("@BPropagationTime",BPropagationTime),
                new System.Data.SqlClient.SqlParameter("@DDuration",DDuration),
                new System.Data.SqlClient.SqlParameter("@DPropagationTime",DPropagationTime),
                new System.Data.SqlClient.SqlParameter("@EDuration",EDuration),
                new System.Data.SqlClient.SqlParameter("@EPropagationTime",EPropagationTime),
                new System.Data.SqlClient.SqlParameter("@JudgeJobCount",JudgeJobCount),
                new System.Data.SqlClient.SqlParameter("@ABJobCount",ABJobCount),
                new System.Data.SqlClient.SqlParameter("@DJobCount",DJobCount),
                new System.Data.SqlClient.SqlParameter("@EJobCount",EJobCount),
                new System.Data.SqlClient.SqlParameter("@StaticID",StaticID),
                new System.Data.SqlClient.SqlParameter("@MachineDistinguishDuration",MachineDistinguishDuration),
                new System.Data.SqlClient.SqlParameter("@MachineDistinguishPropagationTime",MachineDistinguishPropagationTime),
                new System.Data.SqlClient.SqlParameter("@ManualDistinguishDuration",ManualDistinguishDuration),
                new System.Data.SqlClient.SqlParameter("@ManualDistinguishPropagationTime",ManualDistinguishPropagationTime),
                new System.Data.SqlClient.SqlParameter("@UserOrder",UserOrder),
                new System.Data.SqlClient.SqlParameter("@AImageCount",                AImageCount),
                new System.Data.SqlClient.SqlParameter("@BImageCount",                BImageCount),
                new System.Data.SqlClient.SqlParameter("@DImageCount",                DImageCount),
                new System.Data.SqlClient.SqlParameter("@EImageCount",                EImageCount),
                new System.Data.SqlClient.SqlParameter("@TrimerJobCount",             TrimerJobCount),
                new System.Data.SqlClient.SqlParameter("@TrimerImageCount",           TrimerImageCount),
                new System.Data.SqlClient.SqlParameter("@JudegADuration",             JudegADuration),
                new System.Data.SqlClient.SqlParameter("@JudegAPropagationTime",      JudegAPropagationTime),
                new System.Data.SqlClient.SqlParameter("@JudegBDuration",             JudegBDuration),
                new System.Data.SqlClient.SqlParameter("@JudegBPropagationTime",      JudegBPropagationTime),
                new System.Data.SqlClient.SqlParameter("@JudageAJobCount",           JudageAJobCount),
                new System.Data.SqlClient.SqlParameter("@JudageBJobCount",           JudageBJobCount),
                new System.Data.SqlClient.SqlParameter("@JudgeAImageCount",           JudgeAImageCount),
                new System.Data.SqlClient.SqlParameter("@JudgeBImageCount",           JudgeBImageCount),
                new System.Data.SqlClient.SqlParameter("@FJobCount",                  FJobCount),
                new System.Data.SqlClient.SqlParameter("@FDuration",                  FDuration),
                new System.Data.SqlClient.SqlParameter("@FPropagationTime",           FPropagationTime),
                new System.Data.SqlClient.SqlParameter("@FImageCount",                FImageCount),
                new System.Data.SqlClient.SqlParameter("@GJobCount",                  GJobCount),
                new System.Data.SqlClient.SqlParameter("@GDuration",                  GDuration),
                new System.Data.SqlClient.SqlParameter("@GPropagationTime",          GPropagationTime),
                new System.Data.SqlClient.SqlParameter("@GImageCount",                GImageCount),
                new System.Data.SqlClient.SqlParameter("@OrderComment",               OrderComment),
                new System.Data.SqlClient.SqlParameter("@OrderCancelDateTime",        OrderCancelDateTime),
                new System.Data.SqlClient.SqlParameter("@CustomerInformation",        CustomerInformation),
            };

            if (string.IsNullOrEmpty( OrderComment))
            {
                SetEmptyToNull(ref SqlParameter, "@OrderComment");
            }

            if (string.IsNullOrEmpty(CustomerInformation))
            {
                SetEmptyToNull(ref SqlParameter, "@CustomerInformation");
            }

            if (OrderCancelDateTime == null)
            {
                SetEmptyToNull(ref SqlParameter, "@OrderCancelDateTime");
            }

            ExecCommand(orderSql.ToString(), SqlParameter);

        }

      
        public void OrderDelete(Guid OrderID)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append(" DELETE FROM [Orders]");
            orderSql.Append(" WHERE  [OrderID]");
            orderSql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }

        public void OrderDelete(Guid OrderID,string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [Orders] ");
            orderSql.Append("    FROM [Orders] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [Orders].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [Orders].[OrderID] = @OrderID AND[StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }

        #endregion

        #region Jobs

        public   void JobInsert(
            Guid  JobID,Guid OrderID,string JobClass,int CategoryID,string CategoryName
            , string LoginName, DateTime? DLDateTime,DateTime? ULDateTime
            ,double Duration,double PropagationTime,double RecordedDataCount
            ,double RecordedDuration ,double JobLoad
            , double WordCound, DateTime? CreateTime, double DataCount, Guid StaticID
            , double JobDuration,int FileSize
            ,string    ImageType ,string   ScriptType ,string    WordDirection 
            ,string WordFlag ,string    WordType
            , string MatterType, int Warning
            , string IsConstraintEntry
            )
        {
            StringBuilder JobSql = new StringBuilder();
            JobSql.Append(" INSERT INTO [Jobs]");
            JobSql.Append(" (");
            JobSql.Append(" jobID");
            JobSql.Append(" ,OrderID");
            JobSql.Append(" ,JobClass");
            JobSql.Append(" ,CategoryID");
            JobSql.Append(" ,CategoryName");
            JobSql.Append(" ,LoginName");
            JobSql.Append(" ,DLDateTime");
            JobSql.Append(" ,ULDateTime");
            JobSql.Append(" ,Duration");
            JobSql.Append(" ,PropagationTime");
            JobSql.Append(" ,RecordedDataCount");
            JobSql.Append(" ,RecordedDuration"); 
            JobSql.Append(" ,JobLoad");
            JobSql.Append(" ,WordCount");
            JobSql.Append(" ,CreateTime");
            JobSql.Append(" ,DataCount");
            JobSql.Append(" ,StaticID");
            JobSql.Append(" ,JobDuration");
            JobSql.Append(" ,FileSize");
            JobSql.Append(" ,ImageType"); 
            JobSql.Append(" ,ScriptType ");
            JobSql.Append(" ,WordDirection ");
            JobSql.Append(" ,WordFlag ");
            JobSql.Append(" ,WordType ");
            JobSql.Append(" ,MatterType ");
            JobSql.Append(" ,Warning ");
            JobSql.Append(" ,IsConstraintEntry");
            JobSql.Append(" )");
            JobSql.Append(" VALUES");
            JobSql.Append(" (");
            JobSql.Append("  @JobID");
            JobSql.Append(" ,@OrderID");
            JobSql.Append(" ,@JobClass");
            JobSql.Append(" ,@CategoryID");
            JobSql.Append(" ,@CategoryName");
            JobSql.Append(" ,@LoginName" );
            JobSql.Append(" ,@DLDateTime" );
            JobSql.Append(" ,@ULDateTime" );
            JobSql.Append(" ,@Duration" );
            JobSql.Append(" ,@PropagationTime" );
            JobSql.Append(" ,@RecordedDataCount" );
            JobSql.Append(" ,@RecordedDuration" ); 
            JobSql.Append(" ,@JobLoad" );
            JobSql.Append(" ,@WordCound" );
            JobSql.Append(" ,@CreateTime" );
            JobSql.Append(" ,@DataCount" );
            JobSql.Append(" ,@StaticID" );
            JobSql.Append(" ,@JobDuration" );
            JobSql.Append(" ,@FileSize" );
            JobSql.Append(" ,@ImageType" );
            JobSql.Append(" ,@ScriptType" );
            JobSql.Append(" ,@WordDirection" ) ;
            JobSql.Append(" ,@WordFlag" );
            JobSql.Append(" ,@WordType");
            JobSql.Append(" ,@MatterType"  );
            JobSql.Append(" ,@Warning");
            JobSql.Append(" ,@IsConstraintEntry");
            JobSql.Append(" )");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@JobID",	JobID),
                new System.Data.SqlClient.SqlParameter("@OrderID",	@OrderID),
                new System.Data.SqlClient.SqlParameter("@JobClass",	@JobClass),
                new System.Data.SqlClient.SqlParameter("@CategoryID",CategoryID),
                new System.Data.SqlClient.SqlParameter("@CategoryName",CategoryName),
                new System.Data.SqlClient.SqlParameter("@LoginName" ,@LoginName ),
                new System.Data.SqlClient.SqlParameter("@DLDateTime" ,DLDateTime ),
                new System.Data.SqlClient.SqlParameter("@ULDateTime" ,ULDateTime ),
                new System.Data.SqlClient.SqlParameter("@Duration" ,Duration ),
                new System.Data.SqlClient.SqlParameter("@PropagationTime" ,PropagationTime ),
                new System.Data.SqlClient.SqlParameter("@RecordedDataCount" ,RecordedDataCount),
                new System.Data.SqlClient.SqlParameter("@RecordedDuration" ,RecordedDuration ), 
                new System.Data.SqlClient.SqlParameter("@JobLoad" ,JobLoad ),
                new System.Data.SqlClient.SqlParameter("@WordCound" ,WordCound ),
                new System.Data.SqlClient.SqlParameter("@CreateTime" ,CreateTime ),
                new System.Data.SqlClient.SqlParameter("@DataCount",DataCount ),
                new System.Data.SqlClient.SqlParameter("@StaticID" , StaticID ),
                new System.Data.SqlClient.SqlParameter("@JobDuration" ,JobDuration ),
                new System.Data.SqlClient.SqlParameter("@FileSize" ,FileSize ),
                new System.Data.SqlClient.SqlParameter("@ImageType" ,ImageType ),
                new System.Data.SqlClient.SqlParameter("@ScriptType" ,ScriptType ),
                new System.Data.SqlClient.SqlParameter("@WordDirection" ,WordDirection ) ,
                new System.Data.SqlClient.SqlParameter("@WordFlag" ,@WordFlag ),
                new System.Data.SqlClient.SqlParameter("@WordType",WordType ),
                new System.Data.SqlClient.SqlParameter("@MatterType" ,@MatterType  ),
                new System.Data.SqlClient.SqlParameter("@Warning",Warning),
                new System.Data.SqlClient.SqlParameter("@IsConstraintEntry",IsConstraintEntry),



            };

            if ( string.IsNullOrEmpty( LoginName) && ( DLDateTime == null ) &&  (ULDateTime == null) )
            {
                SetEmptyToNull(ref SqlParameter, "@LoginName");
                SetEmptyToNull(ref SqlParameter, "@DLDateTime");
                SetEmptyToNull(ref SqlParameter, "@ULDateTime");
                SetEmptyToNull(ref SqlParameter, "@Duration");
                SetEmptyToNull(ref SqlParameter, "@PropagationTime");
                SetEmptyToNull(ref SqlParameter, "@RecordedDataCount");
                SetEmptyToNull(ref SqlParameter, "@RecordedDuration");
                SetEmptyToNull(ref SqlParameter, "@WordCound");
                SetEmptyToNull(ref SqlParameter, "@JobLoad");
                SetEmptyToNull(ref SqlParameter, "@JobDuration"); 

            }


            ExecCommand(JobSql.ToString(),SqlParameter);

        }

        public void JobDelete(Guid OrderID)
        {
            StringBuilder  Sql = new StringBuilder();

             Sql.Append(" DELETE FROM [Jobs]");
             Sql.Append(" WHERE  [OrderID]");
             Sql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand( Sql.ToString(), SqlParameter);
        }

        public void JobDelete(Guid OrderID,string ServerName)
        {
            StringBuilder Sql = new StringBuilder();

            Sql.Append("        DELETE [Jobs] FROM [Jobs] ");
            Sql.Append("              INNER JOIN [StaticState] ON [Jobs].[StaticID] = [StaticState].[StaticID]");
            Sql.Append("       WHERE  [Jobs].[OrderID] = @OrderID AND[StaticState].Memo = @ServerName");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                 new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
            };

            ExecCommand(Sql.ToString(), SqlParameter);
        }
        #endregion

        #region ParentObject

        public void ParentInsert(Guid ParentID, Guid OrderID, double FrameCount, string FileName, Guid StaticID)
        {
            StringBuilder ParentSql = new StringBuilder();
            ParentSql.Append(" INSERT INTO [ParentObject]");
            ParentSql.Append("(");
            ParentSql.Append(" ParentID");
            ParentSql.Append(" ,OrderID");
            ParentSql.Append(" ,FrameCount");
            ParentSql.Append(" ,FileName");
            ParentSql.Append(" ,StaticID");
            ParentSql.Append(")");
            ParentSql.Append(" VALUES");
            ParentSql.Append("(");
            ParentSql.Append("  @ParentID" );
            ParentSql.Append(" ,@OrderID" );
            ParentSql.Append(" ,@FrameCount");
            ParentSql.Append(" ,@FileName");
            ParentSql.Append(" ,@StaticID" );
            ParentSql.Append(")");

              System.Data.SqlClient.SqlParameter[] SqlParameter;
              SqlParameter = new System.Data.SqlClient.SqlParameter[]
            { 
                new System.Data.SqlClient.SqlParameter("@ParentID",ParentID),         
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                new System.Data.SqlClient.SqlParameter("@FrameCount",FrameCount),
                new System.Data.SqlClient.SqlParameter("@FileName",FileName),
                new System.Data.SqlClient.SqlParameter("@StaticID",StaticID),
            };

              ExecCommand(ParentSql.ToString(), SqlParameter);
        }

        public void ParentDelete(Guid OrderID)
        {
            StringBuilder  Sql = new StringBuilder();

             Sql.Append(" DELETE FROM [ParentObject]");
             Sql.Append(" WHERE  [OrderID]");
             Sql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand( Sql.ToString(), SqlParameter);
        }

        public void ParentDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [ParentObject] FROM [ParentObject] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [ParentObject].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [ParentObject].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }

        #endregion

        #region FrameObject

        /// <summary>
        /// 去掉 MTPropagationTime   ,double TrimerPropagationTime
        /// 这个时间不准确
        /// 只有 Job级别才有全部的时长
        /// </summary>
      
        public   void FrameInsert(Guid FrameID ,Guid ParentID,Guid OrderID
            ,int CategoryID,string CategoryName
             ,Guid MTJobID ,Guid TrimerJobID  ,double  MTDuration,double TrimerDuration
            , DateTime? MTInputDateTime, DateTime? TrimerInputDateTime 
             ,double MTBlockCount        , double TrimerBlockCount
             ,int  X ,int Y ,int Width   ,int Height, 
             Guid StaticID
            ,int fileSize
            ,string WordFlag
            ,string WordType //2011-05-04 add
            , int Warning //2011-05-04 add
            , Guid? DataStoreID
            )
        {
            StringBuilder FrameSql = new StringBuilder();
            FrameSql.Append("  INSERT INTO [FrameObject]");
            FrameSql.Append(" (");
            FrameSql.Append(" FrameID");
            FrameSql.Append(" ,ParentID");
            FrameSql.Append(" ,OrderID");
            FrameSql.Append(" ,CategoryID");
            FrameSql.Append(" ,CategoryName");
            FrameSql.Append(" ,MTJobID");
            FrameSql.Append(" ,TrimerJobID");
            FrameSql.Append(" ,MTDuration");
            FrameSql.Append(" ,TrimerDuration");            
            FrameSql.Append(" ,MTInputDateTime");
            FrameSql.Append(" ,TrimerInputDateTime" );
            FrameSql.Append(" ,MTBlockCount");
            FrameSql.Append(" ,TrimerBlockCount");
            FrameSql.Append(" ,X");
            FrameSql.Append(" ,Y");
            FrameSql.Append(" ,Width");
            FrameSql.Append(" ,Height");
            FrameSql.Append(" ,StaticID");
            FrameSql.Append(" ,FileSize");
            FrameSql.Append(" ,WordFlag");
            FrameSql.Append(" ,WordType");
            FrameSql.Append(" ,Warning");
            FrameSql.Append(" ,DataStoreID");
            FrameSql.Append(" )");
            FrameSql.Append(" VALUES");
            FrameSql.Append("(");
            FrameSql.Append("  @FrameID" );
            FrameSql.Append(" ,@ParentID" );
            FrameSql.Append(" ,@OrderID" );
            FrameSql.Append(" ,@CategoryID" );
            FrameSql.Append(" ,@CategoryName" );
            FrameSql.Append(" ,@MTJobID" );
            FrameSql.Append(" ,@TrimerJobID" );
            FrameSql.Append(" ,@MTDuration" );
            FrameSql.Append(" ,@TrimerDuration");

            FrameSql.Append(" ,@MTInputDateTime" );
            FrameSql.Append(" ,@TrimerInputDateTime" );
            FrameSql.Append(" ,@MTBlockCount" );
            FrameSql.Append(" ,@TrimerBlockCount" );
            FrameSql.Append(" ,@X" );
            FrameSql.Append(" ,@Y" );
            FrameSql.Append(" ,@Width" );
            FrameSql.Append(" ,@Height" );
            FrameSql.Append(" ,@StaticID" );
            //2010 05 13
            FrameSql.Append(" ,@fileSize");
            //2011-4-1
            FrameSql.Append(" ,@WordFlag");
            FrameSql.Append(" ,@WordType");
            FrameSql.Append(" ,@Warning");
            FrameSql.Append(" ,@DataStoreID");
            FrameSql.Append(")");

              System.Data.SqlClient.SqlParameter[] SqlParameter;
              SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
               
                new System.Data.SqlClient.SqlParameter("@FrameID",FrameID ),
                new System.Data.SqlClient.SqlParameter("@ParentID" ,ParentID),
                new System.Data.SqlClient.SqlParameter("@OrderID" ,OrderID),
                new System.Data.SqlClient.SqlParameter("@CategoryID" ,CategoryID),
                new System.Data.SqlClient.SqlParameter("@CategoryName" ,CategoryName),
                new System.Data.SqlClient.SqlParameter("@MTJobID",MTJobID ),
                new System.Data.SqlClient.SqlParameter("@TrimerJobID" ,TrimerJobID),
                new System.Data.SqlClient.SqlParameter("@MTDuration" ,MTDuration),
                new System.Data.SqlClient.SqlParameter("@TrimerDuration",TrimerDuration),
                new System.Data.SqlClient.SqlParameter("@MTInputDateTime",MTInputDateTime ),
                new System.Data.SqlClient.SqlParameter("@TrimerInputDateTime" ,TrimerInputDateTime),
                new System.Data.SqlClient.SqlParameter("@MTBlockCount" ,MTBlockCount),
                new System.Data.SqlClient.SqlParameter("@TrimerBlockCount" ,TrimerBlockCount),
                new System.Data.SqlClient.SqlParameter("@X" ,X),
                new System.Data.SqlClient.SqlParameter("@Y" ,Y),
                new System.Data.SqlClient.SqlParameter("@Width",Width ),
                new System.Data.SqlClient.SqlParameter("@Height",Height ),
                new System.Data.SqlClient.SqlParameter("@StaticID" ,StaticID),
                new System.Data.SqlClient.SqlParameter("@fileSize",fileSize) , 
                new System.Data.SqlClient.SqlParameter("@WordFlag",WordFlag) ,  
                new System.Data.SqlClient.SqlParameter("@WordType",WordType) ,  
                new System.Data.SqlClient.SqlParameter("@Warning",Warning) , 
                new System.Data.SqlClient.SqlParameter("@DataStoreID",DataStoreID) , 
            };

            
              //if (MTJobID == Guid.Empty)
              //    SetEmptyToNull(ref SqlParameter, "@MTJobID");
              //if (TrimerJobID == Guid.Empty)
              //    SetEmptyToNull(ref SqlParameter, "@TrimerJobID");

              if ((MTInputDateTime == null) ||(MTInputDateTime == System.DateTime.MinValue))
                  SetEmptyToNull(ref SqlParameter, "@MTInputDateTime");
              if ((TrimerInputDateTime == null)||(TrimerInputDateTime == System.DateTime.MinValue))
                  SetEmptyToNull(ref SqlParameter, "@TrimerInputDateTime");


              ExecCommand(FrameSql.ToString(), SqlParameter);
        }

        public void FrameDelete(Guid OrderID)
        {
            StringBuilder Sql = new StringBuilder();

             Sql.Append(" DELETE FROM [FrameObject]");
             Sql.Append(" WHERE  [OrderID]");
             Sql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand( Sql.ToString(), SqlParameter);
        }

        public void FrameDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [FrameObject] FROM [FrameObject] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [FrameObject].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [FrameObject].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }



        #endregion

        #region BlockObject

        public   void BlockInsert(
              Guid  BlockID 
            ,Guid FrameID  
            ,Guid OrderID   
            ,Guid JobID
            ,int CategoryID
            ,string CategoryName
            , DateTime? OcrInputTime
             ,double OcrDuration 
            ,string  WordDirection
             ,string WordFlag  
            ,string wordType 
            ,string Transverse   
            ,string ManuscriptType
            , int x
            , int y
            , int width
            , int height
            , double inpuobjectCount
            , Guid StaticID
            , int fileSize
            , string  ImageType
            , string MatterType
      
            )
        {
            StringBuilder BlockSql = new StringBuilder();

            BlockSql.Append("  INSERT INTO [BlockObject]");
            BlockSql.Append("(");
            BlockSql.Append(" BlockID");
            BlockSql.Append(" ,FrameID");
            BlockSql.Append(" ,OrderID");
            BlockSql.Append(" ,JobID");
            BlockSql.Append(" ,CategoryID");
            BlockSql.Append(" ,CategoryName");
            BlockSql.Append(" ,OcrInputTime");
            BlockSql.Append(" ,OcrDuration");
            //BlockSql.Append(" ,OcrPropagationTime");
            BlockSql.Append(" ,WordDirection");
            BlockSql.Append(" ,WordFlag");
            BlockSql.Append(" ,wordType");
            BlockSql.Append(" ,Transverse");
            BlockSql.Append(" ,ManuscriptType");
            BlockSql.Append(" ,x");
            BlockSql.Append(" ,y");
            BlockSql.Append(" ,width");
            BlockSql.Append(" ,height");
            BlockSql.Append(" ,inpuobjectCount");
            BlockSql.Append(" ,StaticID");
            BlockSql.Append(" ,FileSize");
            BlockSql.Append(" ,ImageType");
            BlockSql.Append(" ,MatterType");
 
            BlockSql.Append(")");
            BlockSql.Append(" VALUES");
            BlockSql.Append("(");
            BlockSql.Append("   @BlockID ");
            BlockSql.Append(" , @FrameID ");
            BlockSql.Append(" , @OrderID ");
            BlockSql.Append(" , @JobID ");
            BlockSql.Append(" , @CategoryID ");
            BlockSql.Append(" , @CategoryName");
            BlockSql.Append(" , @OcrInputTime ");
            BlockSql.Append(" , @OcrDuration ");
            //BlockSql.Append(" ," + OcrPropagationTime);
            BlockSql.Append(" , @WordDirection ");
            BlockSql.Append(" , @WordFlag ");
            BlockSql.Append(" , @wordType ");
            BlockSql.Append(" , @Transverse ");
            BlockSql.Append(" , @ManuscriptType ");
            BlockSql.Append(" , @x ");
            BlockSql.Append(" , @y ");
            BlockSql.Append(" , @width ");
            BlockSql.Append(" , @height ");
            BlockSql.Append(" , @inpuobjectCount ");
            BlockSql.Append(" , @StaticID " );
            BlockSql.Append(" , @fileSize ");
            BlockSql.Append(" , @ImageType ");
            BlockSql.Append(" , @MatterType ");
 

            BlockSql.Append(")");

               System.Data.SqlClient.SqlParameter[] SqlParameter;
               SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@BlockID",BlockID),
                new System.Data.SqlClient.SqlParameter("@FrameID",FrameID),
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                new System.Data.SqlClient.SqlParameter("@JobID",JobID),
                new System.Data.SqlClient.SqlParameter("@CategoryID",CategoryID),
                new System.Data.SqlClient.SqlParameter("@CategoryName",CategoryName),
                new System.Data.SqlClient.SqlParameter("@OcrInputTime",OcrInputTime),
                new System.Data.SqlClient.SqlParameter("@OcrDuration",OcrDuration),              
                new System.Data.SqlClient.SqlParameter("@WordDirection",WordDirection),
                new System.Data.SqlClient.SqlParameter("@WordFlag",WordFlag),
                new System.Data.SqlClient.SqlParameter("@wordType",wordType),
                new System.Data.SqlClient.SqlParameter("@Transverse",Transverse),
                new System.Data.SqlClient.SqlParameter("@ManuscriptType",ManuscriptType),
                new System.Data.SqlClient.SqlParameter("@x",x),
                new System.Data.SqlClient.SqlParameter("@y",y),
                new System.Data.SqlClient.SqlParameter("@width",width),
                new System.Data.SqlClient.SqlParameter("@height",height),
                new System.Data.SqlClient.SqlParameter("@inpuobjectCount",inpuobjectCount),
                new System.Data.SqlClient.SqlParameter("@StaticID",StaticID ),
                new System.Data.SqlClient.SqlParameter("@fileSize",fileSize),
                new System.Data.SqlClient.SqlParameter("@ImageType",ImageType),
                new System.Data.SqlClient.SqlParameter("@MatterType",MatterType) 
               

            };

               //if (JobID == Guid.Empty)
               //    SetEmptyToNull(ref SqlParameter, "@JobID");


            ExecCommand( BlockSql.ToString() ,SqlParameter);

        }

        public void BlockDelete(Guid OrderID)
        {
            StringBuilder BlockSql = new StringBuilder();

            BlockSql.Append(" DELETE FROM [BlockObject]");
            BlockSql.Append(" WHERE  [OrderID]");
            BlockSql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand(BlockSql.ToString(), SqlParameter);
        }

        public void BlockDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [BlockObject] FROM [BlockObject] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [BlockObject].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [BlockObject].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }

        #endregion

        #region JudgeObject

        public   void JudgeInsert(
             Guid JudgeID
            , Guid InputObectID
            ,int CategoryID
            ,string CategoryName
             , Guid jobid
            , Guid OrderID  
            ,string JobClass
            ,string LoginName
            ,double  Duration 
            ,DateTime? InputDateTime
            ,string Transverse
            ,double  wordcount
            ,double errorCount
            , int InputObjectIndex
            ,int X ,int Y  ,int Width ,int Height
            ,Guid StaticID
            ,int fileSize
          
            )
        {
            StringBuilder JudgeSql = new StringBuilder();

            JudgeSql.Append(" INSERT INTO [JudgeObject]");
            JudgeSql.Append(" (");
            JudgeSql.Append(" JudgeID");
            JudgeSql.Append(" ,InputObectID");
            JudgeSql.Append(" ,CategoryID");
            JudgeSql.Append(" ,CategoryName");
            JudgeSql.Append(" ,jobid");
            JudgeSql.Append(" ,OrderID");
            JudgeSql.Append(" ,JobClass");
            JudgeSql.Append(" ,LoginName");
            JudgeSql.Append(" ,Duration");
            JudgeSql.Append(" ,InputDateTime");  
  
            JudgeSql.Append(" ,Transverse");
            JudgeSql.Append(" ,wordcount");
            JudgeSql.Append(" ,errorCount");
            JudgeSql.Append(" ,InputObjectIndex");
            JudgeSql.Append(" ,X");
            JudgeSql.Append(" ,Y");
            JudgeSql.Append(" ,Width");
            JudgeSql.Append(" ,Height");
            JudgeSql.Append(" ,StaticID");
            JudgeSql.Append(" ,FileSize"); 

            JudgeSql.Append(" )");
            JudgeSql.Append(" VALUES ");
            JudgeSql.Append(" (");
            JudgeSql.Append("  @JudgeID" );
            JudgeSql.Append(" ,@InputObectID");
            JudgeSql.Append(" ,@CategoryID");
            JudgeSql.Append(" ,@CategoryName" );
            JudgeSql.Append(" ,@jobid" );
            JudgeSql.Append(" ,@OrderID" );
            JudgeSql.Append(" ,@JobClass" );
            JudgeSql.Append(" ,@LoginName");
            JudgeSql.Append(" ,@Duration");
            JudgeSql.Append(" ,@InputDateTime");  
            JudgeSql.Append(" ,@Transverse" );
            JudgeSql.Append(" ,@wordcount");
            JudgeSql.Append(" ,@errorCount");
            JudgeSql.Append(" ,@InputObjectIndex");
            JudgeSql.Append(" ,@X");
            JudgeSql.Append(" ,@Y");
            JudgeSql.Append(" ,@Width");
            JudgeSql.Append(" ,@Height");
            JudgeSql.Append(" ,@StaticID" );
            JudgeSql.Append(" ,@fileSize"); 

            JudgeSql.Append(" )");

             System.Data.SqlClient.SqlParameter[] SqlParameter;
             SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@JudgeID",JudgeID ),
                new System.Data.SqlClient.SqlParameter("@InputObectID",InputObectID),
                new System.Data.SqlClient.SqlParameter("@CategoryID",CategoryID),
                new System.Data.SqlClient.SqlParameter("@CategoryName",CategoryName ),
                new System.Data.SqlClient.SqlParameter("@jobid" ,jobid),
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID ),
                new System.Data.SqlClient.SqlParameter("@JobClass" ,JobClass),
                new System.Data.SqlClient.SqlParameter("@LoginName",LoginName),
                new System.Data.SqlClient.SqlParameter("@Duration",Duration),
                new System.Data.SqlClient.SqlParameter("@InputDateTime",InputDateTime),  
                new System.Data.SqlClient.SqlParameter("@Transverse", Transverse),
                new System.Data.SqlClient.SqlParameter("@wordcount",wordcount),
                new System.Data.SqlClient.SqlParameter("@errorCount",errorCount),
                new System.Data.SqlClient.SqlParameter("@InputObjectIndex",InputObjectIndex),
                new System.Data.SqlClient.SqlParameter("@X",X),
                new System.Data.SqlClient.SqlParameter("@Y",Y),
                new System.Data.SqlClient.SqlParameter("@Width",Width),
                new System.Data.SqlClient.SqlParameter("@Height",Height),
                new System.Data.SqlClient.SqlParameter("@StaticID",StaticID ),
                new System.Data.SqlClient.SqlParameter("@fileSize",fileSize),  
            };

            ExecCommand(JudgeSql.ToString(),SqlParameter);
        }


        public void JudgeDelete(Guid OrderID)
        {
            StringBuilder  Sql = new StringBuilder();

             Sql.Append(" DELETE FROM [JudgeObject]");
            Sql.Append(" WHERE  [OrderID]");
             Sql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand( Sql.ToString(), SqlParameter);
        }

        public void JudgeDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [JudgeObject] FROM [JudgeObject] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [JudgeObject].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [JudgeObject].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }

        #endregion

        #region JudgeResult

        public   void JudgeResultInsert( 
              Guid JudgeID
              , Guid OrderID
             
             ,string CandidacyJudgeResult1
             ,string CandidacyJudgeResult2
             ,string CandidacyJudgeResult3
             ,string CandidacyJudgeResult4
             ,string CandidacyJudgeResult5
             ,string Result
             ,string LoginName      
             ,string JobClass
             , Guid StaticID
             ,int JudgeNO
             , string IsNullResult
           
            )
        {
            StringBuilder JudgeResultSql = new StringBuilder();
      
            JudgeResultSql.Append(" INSERT INTO [JudgeResult]");
            JudgeResultSql.Append(" (");
            JudgeResultSql.Append(" JudgeID");
            JudgeResultSql.Append(" ,OrderID");
            JudgeResultSql.Append(" ,CandidacyJudgeResult1");
            JudgeResultSql.Append(" ,CandidacyJudgeResult2");
            JudgeResultSql.Append(" ,CandidacyJudgeResult3");
            JudgeResultSql.Append(" ,CandidacyJudgeResult4");
            JudgeResultSql.Append(" ,CandidacyJudgeResult5");
            JudgeResultSql.Append(" ,Result");
            JudgeResultSql.Append(" ,LoginName"); 
            JudgeResultSql.Append(" ,JobClass");
            JudgeResultSql.Append(" ,JudgeNO");
            JudgeResultSql.Append(" ,IsNullResult");
            JudgeResultSql.Append(" ,StaticID");
            JudgeResultSql.Append("");
            JudgeResultSql.Append(" )");
            JudgeResultSql.Append(" VALUES ");
            JudgeResultSql.Append(" (");
            JudgeResultSql.Append("");
            JudgeResultSql.Append("  @JudgeID");
            JudgeResultSql.Append(" ,@OrderID");
            JudgeResultSql.Append(" ,@CandidacyJudgeResult1");
            JudgeResultSql.Append(" ,@CandidacyJudgeResult2");
            JudgeResultSql.Append(" ,@CandidacyJudgeResult3");
            JudgeResultSql.Append(" ,@CandidacyJudgeResult4");
            JudgeResultSql.Append(" ,@CandidacyJudgeResult5");
            JudgeResultSql.Append(" ,@Result");
            JudgeResultSql.Append(" ,@LoginName"); 
            JudgeResultSql.Append(" ,@JobClass");
            JudgeResultSql.Append(" ,@JudgeNO");
            JudgeResultSql.Append(" ,@IsNullResult");
            JudgeResultSql.Append(" ,@StaticID");
            JudgeResultSql.Append(" )");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
             new System.Data.SqlClient.SqlParameter("@JudgeID",JudgeID),
             new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
             new System.Data.SqlClient.SqlParameter("@CandidacyJudgeResult1",CandidacyJudgeResult1),
             new System.Data.SqlClient.SqlParameter("@CandidacyJudgeResult2",CandidacyJudgeResult2),
             new System.Data.SqlClient.SqlParameter("@CandidacyJudgeResult3",CandidacyJudgeResult3),
             new System.Data.SqlClient.SqlParameter("@CandidacyJudgeResult4",CandidacyJudgeResult4),
             new System.Data.SqlClient.SqlParameter("@CandidacyJudgeResult5",CandidacyJudgeResult5),
             new System.Data.SqlClient.SqlParameter("@Result",Result),
             new System.Data.SqlClient.SqlParameter("@LoginName",LoginName), 
             new System.Data.SqlClient.SqlParameter("@JobClass",JobClass),
             new System.Data.SqlClient.SqlParameter("@JudgeNO",JudgeNO),
             new System.Data.SqlClient.SqlParameter("@IsNullResult",IsNullResult),
             new System.Data.SqlClient.SqlParameter("@StaticID",StaticID),
        };
             

           
            ExecCommand(JudgeResultSql.ToString(),SqlParameter);

        }


        public void JudgeResultDelete(Guid OrderID)
        {
            StringBuilder Sql = new StringBuilder();

            Sql.Append(" DELETE FROM [JudgeResult]");
            Sql.Append(" WHERE  [OrderID]");
            Sql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand(Sql.ToString(), SqlParameter);
        }

        public void JudgeResultDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [JudgeResult] FROM [JudgeResult] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [JudgeResult].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [JudgeResult].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }

        #endregion

        #region InputObject

        public   void InputObjectInsert( Guid    InputObject ,Guid BlockID
             ,Guid FrameID  
             ,Guid  OrderID,int CategoryID    ,string CategoryName
              ,double WordCount
             ,double αDuration  
             ,double βDuration   
             ,string  αβAttachWordsResult  
             ,string  αβAttachFlag
             ,int JudgeErrorCount
             ,string AResult   
             ,string Acomment   
             ,double ADuration    
             ,Guid?  AJobID   
             ,string ALoginName    
             ,string BResult
             ,string BComment    
             ,double BDuration   
             ,Guid  BJobID, string BLoginName
             ,string DResult,string  DComment ,double  DDuration
             ,Guid  DJobID ,string DLoginName
             ,string EResult      ,string  EComment,double  EDuration
             ,Guid EJobID,string ELoginName
             ,string FinalResult   ,string FinalComment
             , int BlockObjectIndex
             ,int X      ,int Y   ,int Width,int Height  
             ,string Transverse
             , string WordDirection
            , string ScriptType
            , string WordType
            , Guid StaticID

            ,string AEntryWords
            ,string BEntryWords
            ,int fileSize
            ,string ImageType
            ,string MatterType

            ,string ocrResult
	        ,string judgeAResult
	        ,double judgeADuration

	        ,Guid   judgeJobID
	        ,string judgeALoginName
	        
            ,string judgeBResult
	        ,double judgeBDuration
	        ,string judgeBLoginName
            ,int warning
            //,int isDelivery
            , Guid? DataStoreID
            ,string FinalResultSplit
            )
        {
            StringBuilder InputSql = new StringBuilder();
            InputSql.Append("   INSERT INTO [InputObject]");
            InputSql.Append(" (");
            InputSql.Append(" InputObjectID");
            InputSql.Append(" ,BlockID");
            InputSql.Append(" ,FrameID");
            InputSql.Append(" ,OrderID");
            InputSql.Append(" ,CategoryID");
            InputSql.Append(" ,CategoryName");            
            InputSql.Append(" ,WordCount");
            InputSql.Append(" ,αDuration");
        
            InputSql.Append(" ,βDuration");

            InputSql.Append(" ,αβAttachWordsResult");
            InputSql.Append(" ,αβAttachFlag");
            InputSql.Append(" ,JudgeErrorCount");
            InputSql.Append(" ,AResult");
            InputSql.Append(" ,AComment");
            InputSql.Append(" ,ADuration");

            InputSql.Append(" ,AJobID");
            InputSql.Append(" ,ALoginName");
            InputSql.Append(" ,BResult");
            InputSql.Append(" ,BComment");
            InputSql.Append(" ,BDuration");

            InputSql.Append(" ,BJobID");
            InputSql.Append(" ,BLoginName");
            InputSql.Append(" ,DResult");
            InputSql.Append(" ,DComment");
            InputSql.Append(" ,DDuration");

            InputSql.Append(" ,DJobID");
            InputSql.Append(" ,DLoginName");
            InputSql.Append(" ,EResult");
            InputSql.Append(" ,EComment");
            InputSql.Append(" ,EDuration");

            InputSql.Append(" ,EJobID");
            InputSql.Append(" ,ELoginName");
            InputSql.Append(" ,FinalResult");
            InputSql.Append(" ,FinalComment");
            InputSql.Append(" ,BlockObjectIndex");
            InputSql.Append(" ,x");
            InputSql.Append(" ,y");
            InputSql.Append(" ,width");
            InputSql.Append(" ,height");
            InputSql.Append(" ,Transverse");
            InputSql.Append(" ,WordDirection");
            InputSql.Append(" ,ScriptType");
            InputSql.Append(" ,WordType");
            InputSql.Append(" ,StaticID");
            InputSql.Append(" ,AEntryWords");
            InputSql.Append(" ,BEntryWords");
            InputSql.Append(" ,FileSize");
            InputSql.Append(" ,ImageType");
            InputSql.Append(" ,MatterType");

            InputSql.Append(" ,OcrResult");
            InputSql.Append(" ,JudgeAResult");
            InputSql.Append(" ,JudgeADuration");
            InputSql.Append(" ,JudgeJobID");
            InputSql.Append(" ,JudgeALoginName");
            InputSql.Append(" ,JudgeBResult");
            InputSql.Append(" ,JudgeBDuration");
            InputSql.Append(" ,JudgeBLoginName");
            InputSql.Append(" ,Warning");
            //InputSql.Append(",IsDelivery");
            InputSql.Append(" ,DataStoreID");
            InputSql.Append(" ,FinalResultSplit");

            InputSql.Append(" )");
            InputSql.Append(" VALUES");
            InputSql.Append(" (");
            InputSql.Append("  @InputObject");
            InputSql.Append(" ,@BlockID");
            InputSql.Append(" ,@FrameID");
            InputSql.Append(" ,@OrderID");
            InputSql.Append(" ,@CategoryID");
            InputSql.Append(" ,@CategoryName");
            InputSql.Append(" ,@WordCount");
            InputSql.Append(" ,@αDuration");

            InputSql.Append(" ,@βDuration");

            InputSql.Append(" ,@αβAttachWordsResult");
            InputSql.Append(" ,@αβAttachFlag");
            InputSql.Append(" ,@JudgeErrorCount");
            InputSql.Append(" ,@AResult");
            InputSql.Append(" ,@Acomment");
            InputSql.Append(" ,@ADuration");

            InputSql.Append(" ,@AJobID");
            InputSql.Append(" ,@ALoginName");
            InputSql.Append(" ,@BResult");
            InputSql.Append(" ,@BComment");
            InputSql.Append(" ,@BDuration");

            InputSql.Append(" ,@BJobID");
            InputSql.Append(" ,@BLoginName");
            InputSql.Append(" ,@DResult");
            InputSql.Append(" ,@DComment");
            InputSql.Append(" ,@DDuration");

            InputSql.Append(" ,@DJobID");
            InputSql.Append(" ,@DLoginName");
            InputSql.Append(" ,@EResult");
            InputSql.Append(" ,@EComment");
            InputSql.Append(" ,@EDuration");

            InputSql.Append(" ,@EJobID");
            InputSql.Append(" ,@ELoginName");
            InputSql.Append(" ,@FinalResult");
            InputSql.Append(" ,@FinalComment");
            InputSql.Append(" ,@BlockObjectIndex");
            InputSql.Append(" ,@X");
            InputSql.Append(" ,@Y");
            InputSql.Append(" ,@Width");
            InputSql.Append(" ,@Height"); 
            InputSql.Append(" ,@Transverse");
            InputSql.Append(" ,@WordDirection");
            InputSql.Append(" ,@ScriptType");
            InputSql.Append(" ,@WordType");
            InputSql.Append(" ,@StaticID ");
            InputSql.Append(" ,@AEntryWords");
            InputSql.Append(" ,@BEntryWords");
            InputSql.Append(" ,@FileSize");
            InputSql.Append(" ,@ImageType");
            InputSql.Append(" ,@MatterType");

            InputSql.Append(" ,@OcrResult");
            InputSql.Append(" ,@JudgeAResult");
            InputSql.Append(" ,@JudgeADuration");
            InputSql.Append(" ,@JudgeJobID");
            InputSql.Append(" ,@JudgeALoginName");
            InputSql.Append(" ,@JudgeBResult");
            InputSql.Append(" ,@JudgeBDuration");

            InputSql.Append(" ,@JudgeBLoginName");
            InputSql.Append(" ,@Warning");
            //InputSql.Append(" ,@IsDelivery");
            InputSql.Append(" ,@DataStoreID");
            InputSql.Append(" ,@FinalResultSplit");

            InputSql.Append(" )");

              System.Data.SqlClient.SqlParameter[] SqlParameter;
              SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@InputObject",InputObject),
                new System.Data.SqlClient.SqlParameter("@BlockID",BlockID),
                new System.Data.SqlClient.SqlParameter("@FrameID",FrameID),
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                new System.Data.SqlClient.SqlParameter("@CategoryID",CategoryID),
                new System.Data.SqlClient.SqlParameter("@CategoryName",CategoryName),
                new System.Data.SqlClient.SqlParameter("@WordCount",WordCount),
                new System.Data.SqlClient.SqlParameter("@αDuration",αDuration), 

                new System.Data.SqlClient.SqlParameter("@βDuration",βDuration),

                new System.Data.SqlClient.SqlParameter("@αβAttachWordsResult",αβAttachWordsResult),
                new System.Data.SqlClient.SqlParameter("@αβAttachFlag",αβAttachFlag),
                new System.Data.SqlClient.SqlParameter("@JudgeErrorCount",JudgeErrorCount),
                new System.Data.SqlClient.SqlParameter("@AResult",AResult),
                new System.Data.SqlClient.SqlParameter("@Acomment",Acomment),
                new System.Data.SqlClient.SqlParameter("@ADuration",ADuration),

                new System.Data.SqlClient.SqlParameter("@AJobID",AJobID),
                new System.Data.SqlClient.SqlParameter("@ALoginName",ALoginName),
                new System.Data.SqlClient.SqlParameter("@BResult",@BResult),
                new System.Data.SqlClient.SqlParameter("@BComment",BComment),
                new System.Data.SqlClient.SqlParameter("@BDuration",BDuration),

                new System.Data.SqlClient.SqlParameter("@BJobID",BJobID),
                new System.Data.SqlClient.SqlParameter("@BLoginName",BLoginName),
                new System.Data.SqlClient.SqlParameter("@DResult",DResult),
                new System.Data.SqlClient.SqlParameter("@DComment",DComment),
                new System.Data.SqlClient.SqlParameter("@DDuration",DDuration),

                new System.Data.SqlClient.SqlParameter("@DJobID",DJobID),
                new System.Data.SqlClient.SqlParameter("@DLoginName",DLoginName),
                new System.Data.SqlClient.SqlParameter("@EResult",EResult),
                new System.Data.SqlClient.SqlParameter("@EComment",EComment),
                new System.Data.SqlClient.SqlParameter("@EDuration",EDuration),

                new System.Data.SqlClient.SqlParameter("@EJobID",EJobID),
                new System.Data.SqlClient.SqlParameter("@ELoginName",ELoginName),
                new System.Data.SqlClient.SqlParameter("@FinalResult",FinalResult),
                new System.Data.SqlClient.SqlParameter("@FinalComment",FinalComment),
                new System.Data.SqlClient.SqlParameter("@BlockObjectIndex",BlockObjectIndex),
                new System.Data.SqlClient.SqlParameter("@X",X),
                new System.Data.SqlClient.SqlParameter("@Y",Y),
                new System.Data.SqlClient.SqlParameter("@Width",Width),
                new System.Data.SqlClient.SqlParameter("@Height",Height),
                new System.Data.SqlClient.SqlParameter("@Transverse",Transverse),
                new System.Data.SqlClient.SqlParameter("@WordDirection",WordDirection),
                new System.Data.SqlClient.SqlParameter("@ScriptType",ScriptType),
                new System.Data.SqlClient.SqlParameter("@WordType",WordType),

                new System.Data.SqlClient.SqlParameter("@StaticID ",StaticID ),
                new System.Data.SqlClient.SqlParameter("@AEntryWords",AEntryWords),
                new System.Data.SqlClient.SqlParameter("@BEntryWords",BEntryWords),
                new System.Data.SqlClient.SqlParameter("@FileSize",fileSize),
                new System.Data.SqlClient.SqlParameter("@ImageType",ImageType),
                new System.Data.SqlClient.SqlParameter("@MatterType",MatterType),
                // lidawei  add 2011-1-24
                new System.Data.SqlClient.SqlParameter("@OcrResult",ocrResult),
                new System.Data.SqlClient.SqlParameter("@JudgeAResult",judgeAResult),
                new System.Data.SqlClient.SqlParameter("@JudgeADuration",judgeADuration),
            
                new System.Data.SqlClient.SqlParameter("@JudgeJobID",judgeJobID),
                new System.Data.SqlClient.SqlParameter("@JudgeALoginName",judgeALoginName),
                new System.Data.SqlClient.SqlParameter("@JudgeBResult",judgeBResult),
                new System.Data.SqlClient.SqlParameter("@JudgeBDuration",judgeBDuration), 
                new System.Data.SqlClient.SqlParameter("@JudgeBLoginName",judgeBLoginName),
                //2011-3-20 lidawei R32
                //new System.Data.SqlClient.SqlParameter("@IsDelivery",isDelivery),
                
                new System.Data.SqlClient.SqlParameter("@Warning",warning ),
                new System.Data.SqlClient.SqlParameter("@DataStoreID",DataStoreID) , 
                new System.Data.SqlClient.SqlParameter("@FinalResultSplit",FinalResultSplit),

                };


              //if (InputObject == Guid.Empty)
              //    SetEmptyToNull(ref SqlParameter, "@InputObject");

              //if (BlockID == Guid.Empty)
              //    SetEmptyToNull(ref SqlParameter, "@BlockID");

              //if (FrameID == Guid.Empty)
              //    SetEmptyToNull(ref SqlParameter, "@FrameID");

              //if (OrderID == Guid.Empty)
              //    SetEmptyToNull(ref SqlParameter, "@OrderID");

              //if (αDuration + βDuration == 0)
              //{
              //     SetEmptyToNull(ref SqlParameter, "@αDuration");
              //     SetEmptyToNull(ref SqlParameter, "@βDuration");
              //     SetEmptyToNull(ref SqlParameter, "@αβAttachWordsResult");
              //     SetEmptyToNull(ref SqlParameter, "@αβAttachFlag");
              //     SetEmptyToNull(ref SqlParameter, "@JudgeErrorCount");
 
              //}

              //if (AJobID == Guid.Empty)
              //{
              //    //SetEmptyToNull(ref SqlParameter, "@AJobID");
              //    SetEmptyToNull(ref SqlParameter, "@Acomment");
              //    SetEmptyToNull(ref SqlParameter, "@ADuration");
              //    SetEmptyToNull(ref SqlParameter, "@ALoginName");
              //    SetEmptyToNull(ref SqlParameter, "@AResult");

              //    SetEmptyToNull(ref SqlParameter, "@AEntryWords"); 
              //}

              //if (BJobID == Guid.Empty)
              //{ 
              //    //SetEmptyToNull(ref SqlParameter, "@BJobID");
              //    SetEmptyToNull(ref SqlParameter, "@BComment");
              //    SetEmptyToNull(ref SqlParameter, "@BDuration");
              //    SetEmptyToNull(ref SqlParameter, "@BLoginName");
              //    SetEmptyToNull(ref SqlParameter, "@BResult");
              //    SetEmptyToNull(ref SqlParameter, "@BEntryWords"); 
              
              //}

              //if (DJobID == Guid.Empty)
              //{
              //    //SetEmptyToNull(ref SqlParameter, "@DJobID");
              //    SetEmptyToNull(ref SqlParameter, "@DComment");
              //    SetEmptyToNull(ref SqlParameter, "@DDuration");
              //    SetEmptyToNull(ref SqlParameter, "@DLoginName");
              //    SetEmptyToNull(ref SqlParameter, "@DResult");
              //}

              //if (EJobID == Guid.Empty)
              //{
              //    //SetEmptyToNull(ref SqlParameter, "@EJobID");
              //    SetEmptyToNull(ref SqlParameter, "@EComment");
              //    SetEmptyToNull(ref SqlParameter, "@EDuration");
              //    SetEmptyToNull(ref SqlParameter, "@ELoginName");
              //    SetEmptyToNull(ref SqlParameter, "@EResult");
              //}

              //if ( judgeJobID == Guid.Empty)
              //{
              //    //SetEmptyToNull(ref SqlParameter, "@JudgeJobID");
              //    SetEmptyToNull(ref SqlParameter, "@JudgeAResult");
              //    SetEmptyToNull(ref SqlParameter, "@JudgeADuration");
              //    SetEmptyToNull(ref SqlParameter, "@ELoginName");
              //    //SetEmptyToNull(ref SqlParameter, "@JudgeJobID");
              //    SetEmptyToNull(ref SqlParameter,"@JudgeALoginName");
              //    SetEmptyToNull(ref SqlParameter,"@JudgeBResult");
              //    SetEmptyToNull(ref SqlParameter,"@JudgeBDuration");
              //    SetEmptyToNull(ref SqlParameter , "@JudgeBLoginName");
              // }

              //if (FinalResult == string.Empty && FinalComment == string.Empty)
              //{
              //    SetEmptyToNull(ref SqlParameter, "@FinalResult");
              //    SetEmptyToNull(ref SqlParameter, "@FinalComment"); 
              //}
 
            ExecCommand(InputSql.ToString(),SqlParameter);
        }



        public void InputDelete(Guid OrderID)
        {
            StringBuilder Sql = new StringBuilder();

            Sql.Append(" DELETE FROM [InputObject]");
            Sql.Append(" WHERE  [OrderID]");
            Sql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand(Sql.ToString(), SqlParameter);
        }

        public void InputDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [InputObject] FROM [InputObject] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [InputObject].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [InputObject].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }

        #endregion

        #region DataExceptionLog

        public void ExceptionInsert(string Contents, string Details)
        {
            StringBuilder ExceptionSql = new StringBuilder();
            ExceptionSql.Append(" INSERT INTO [DataExceptionLog]");
            ExceptionSql.Append("(");
            ExceptionSql.Append(" [Contents]");
            ExceptionSql.Append(",[Detail]");
            ExceptionSql.Append(",[UpdateTime]");
            ExceptionSql.Append(")");
            ExceptionSql.Append(" VALUES");
            ExceptionSql.Append("(");
            ExceptionSql.Append(" @Contents");
            ExceptionSql.Append(",@Detail");
            ExceptionSql.Append(",@UpdateTime");
            ExceptionSql.Append(")");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
             new System.Data.SqlClient.SqlParameter("@Contents",Contents),
             new System.Data.SqlClient.SqlParameter("@Detail",Details),
             new System.Data.SqlClient.SqlParameter("@UpdateTime",System.DateTime.Now) 
        };

            ExecCommand(ExceptionSql.ToString(),SqlParameter);
        }

        #endregion

        #region ProgressResult
        public void  ProgressResultInsert(Guid Orderid, Guid progressID
           ,string argJobclass  ,int ArgFlow  ,string ArgStartDatetime
           ,string ArgFinishedDatetime,string ResultClass   ,Guid StaticID)
        {
            StringBuilder ProgressResultSql = new StringBuilder();
            ProgressResultSql.Append(" INSERT INTO [ProgressResult]");
            ProgressResultSql.Append("(");
            ProgressResultSql.Append(" [OrderID]");
            ProgressResultSql.Append(" ,[progressID]");
            ProgressResultSql.Append(" ,[argJobclass]");
            ProgressResultSql.Append(" ,[ArgFlow]");
            ProgressResultSql.Append(" ,[ArgStartDatetime]");
            ProgressResultSql.Append(" ,[ArgFinishedDatetime]");
            ProgressResultSql.Append(" ,[ResultClass]");
            ProgressResultSql.Append(" ,[StaticID] ");
             ProgressResultSql.Append(")");
             ProgressResultSql.Append(" VALUES");
             ProgressResultSql.Append("(");
             ProgressResultSql.Append(" @OrderID");
             ProgressResultSql.Append(" ,@progressID");
             ProgressResultSql.Append(" ,@argJobclass");
             ProgressResultSql.Append(" ,@ArgFlow");
             ProgressResultSql.Append(" ,@ArgStartDatetime");
             ProgressResultSql.Append(" ,@ArgFinishedDatetime");
             ProgressResultSql.Append(" ,@ResultClass");
             ProgressResultSql.Append(" ,@StaticID ");
             ProgressResultSql.Append(")");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
             new System.Data.SqlClient.SqlParameter("@OrderID",Orderid),
             new System.Data.SqlClient.SqlParameter("@progressID",progressID),
             new System.Data.SqlClient.SqlParameter("@argJobclass",argJobclass) ,
             new System.Data.SqlClient.SqlParameter("@ArgFlow",ArgFlow),             
             new System.Data.SqlClient.SqlParameter("@ArgStartDatetime",ArgStartDatetime) , 
             new System.Data.SqlClient.SqlParameter("@ArgFinishedDatetime",ArgFinishedDatetime) ,

             new System.Data.SqlClient.SqlParameter("@ResultClass",ResultClass) , 
             new System.Data.SqlClient.SqlParameter("@StaticID",StaticID) , 


        };

            ExecCommand(ProgressResultSql.ToString(), SqlParameter);
        }

        public void ProgressResultDelete(Guid Orderid)
        {
             
            StringBuilder Sql = new StringBuilder();

            Sql.Append(" DELETE FROM [ProgressResult]");
            Sql.Append(" WHERE  [OrderID]");
            Sql.Append(" = @OrderID");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {          
                new System.Data.SqlClient.SqlParameter("@OrderID",Orderid),
            };

            ExecCommand(Sql.ToString(), SqlParameter);
        }

        public void ProgressResultDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [ProgressResult] FROM [ProgressResult] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [ProgressResult].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [ProgressResult].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }
        #endregion ProgressResult

        #region DistinguishObject

        public void DistinguishObjectInsert( Guid DistinguishID,Guid ParentID,	Guid OrderID,
	            int CategoryID ,string CategoryName,Guid JobID,string JobClass,double Duration,
	            DateTime InputDateTime,string Transverse,string Result,int X,int Y,int Width, int Height, Guid StaticID
            ,int fileSize)
        {
            StringBuilder DistinguishSql = new StringBuilder();
    
            DistinguishSql.Append ( " INSERT INTO  [DistinguishObject] ");
            DistinguishSql.Append ( " ([DistinguishID] ");
            DistinguishSql.Append ( " ,[ParentID] ");
            DistinguishSql.Append ( " ,[OrderID] ");
            DistinguishSql.Append ( " ,[CategoryID] ");
            DistinguishSql.Append ( " ,[CategoryName] ");
            DistinguishSql.Append ( " ,[JobID] ");
            DistinguishSql.Append ( " ,[JobClass] ");
            DistinguishSql.Append ( " ,[Duration] ");
            DistinguishSql.Append ( " ,[InputDateTime] ");
            DistinguishSql.Append ( " ,[Transverse] ");
            DistinguishSql.Append ( " ,[Result] ");
            DistinguishSql.Append ( " ,[X] ");
            DistinguishSql.Append ( " ,[Y] ");
            DistinguishSql.Append ( " ,[Width] ");
            DistinguishSql.Append ( " ,[Height] ");
            DistinguishSql.Append(" ,[StaticID]");
            DistinguishSql.Append(" ,[FileSize]");

            DistinguishSql.Append ( "     ) ");
            DistinguishSql.Append ( " VALUES ");
            DistinguishSql.Append ( " ( @DistinguishID ");
            DistinguishSql.Append ( " ,@ParentID ");
            DistinguishSql.Append ( " ,@OrderID ");
            DistinguishSql.Append ( " ,@CategoryID ");
            DistinguishSql.Append ( " ,@CategoryName ");
            DistinguishSql.Append ( " ,@JobID ");
            DistinguishSql.Append ( " ,@JobClass ");
            DistinguishSql.Append ( " ,@Duration ");
            DistinguishSql.Append ( " ,@InputDateTime ");
            DistinguishSql.Append ( " ,@Transverse ");
            DistinguishSql.Append ( " ,@Result ");
            DistinguishSql.Append ( " ,@X ");
            DistinguishSql.Append ( " ,@Y ");
            DistinguishSql.Append ( " ,@Width ");
            DistinguishSql.Append ( " ,@Height ");
            DistinguishSql.Append ( " ,@StaticID ");
            DistinguishSql.Append(" ,@FileSize");
            DistinguishSql.Append("     )");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
                new System.Data.SqlClient.SqlParameter("@DistinguishID",DistinguishID),
                new System.Data.SqlClient.SqlParameter("@ParentID",ParentID),
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                new System.Data.SqlClient.SqlParameter("@CategoryID",CategoryID),
                new System.Data.SqlClient.SqlParameter("@CategoryName",CategoryName),
                new System.Data.SqlClient.SqlParameter("@JobID",JobID),
                new System.Data.SqlClient.SqlParameter("@JobClass",JobClass),
                new System.Data.SqlClient.SqlParameter("@Duration",Duration),
                new System.Data.SqlClient.SqlParameter("@InputDateTime",InputDateTime),
                new System.Data.SqlClient.SqlParameter("@Transverse",Transverse),
                new System.Data.SqlClient.SqlParameter("@Result",Result),
                new System.Data.SqlClient.SqlParameter("@X",X),
                new System.Data.SqlClient.SqlParameter("@Y",Y),
                new System.Data.SqlClient.SqlParameter("@Width",Width),
                new System.Data.SqlClient.SqlParameter("@Height",Height),
                new System.Data.SqlClient.SqlParameter("@StaticID",StaticID), 
                new System.Data.SqlClient.SqlParameter("@FileSize",fileSize), 

            };

             ExecCommand(DistinguishSql.ToString(), SqlParameter);
        }

        public void DistinguishObjectDelete( Guid OrderID )
        {
            StringBuilder DistinguishSql = new StringBuilder();

            DistinguishSql.Append(" DELETE FROM [DistinguishObject] WHERE [OrderID] = @OrderID");
             System.Data.SqlClient.SqlParameter[] SqlParameter;
             SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand(DistinguishSql.ToString(), SqlParameter);
        }

        public void DistinguishObjectDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [DistinguishObject] FROM [DistinguishObject] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [DistinguishObject].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [DistinguishObject].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }


        #endregion

        #region CancelJobLogs

        public void CancelJobLogsInsert(Guid jobID, Guid orderID, string loginName, DateTime? cancelDatetime, Guid staticID)
        {
            StringBuilder CancelJobLogsSql = new StringBuilder();

            CancelJobLogsSql.Append(" INSERT INTO [CancelJobLogs] ");
            CancelJobLogsSql.Append(" ([JobID] ");
            CancelJobLogsSql.Append(" ,[OrderID] ");
            CancelJobLogsSql.Append(" ,[LoginName] ");
            CancelJobLogsSql.Append(" ,[CancelDateTime] ");
            CancelJobLogsSql.Append(" ,[StaticID]) ");
            CancelJobLogsSql.Append(" VALUES ");
            CancelJobLogsSql.Append(" ( ");
            CancelJobLogsSql.Append("  @JobID ");
            CancelJobLogsSql.Append(" ,@OrderID ");
            CancelJobLogsSql.Append(" ,@LoginName ");
            CancelJobLogsSql.Append(" ,@CancelDateTime ");
            CancelJobLogsSql.Append(" ,@StaticID ");
            CancelJobLogsSql.Append(" ) ");



            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
                new System.Data.SqlClient.SqlParameter("@JobID",jobID ),
                new System.Data.SqlClient.SqlParameter("@OrderID",orderID ),
                new System.Data.SqlClient.SqlParameter("@LoginName",loginName ),
                new System.Data.SqlClient.SqlParameter("@CancelDateTime",cancelDatetime ),
                new System.Data.SqlClient.SqlParameter("@StaticID",staticID ),
               

            };

            ExecCommand(CancelJobLogsSql.ToString(), SqlParameter);
        }

        public void CancelJobLogsDelete( Guid orderID )
        {
            StringBuilder CancelJobLogsSql = new StringBuilder();

            CancelJobLogsSql.Append(" DELETE FROM [CancelJobLogs] WHERE [OrderID] = @OrderID");
            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
                new System.Data.SqlClient.SqlParameter("@OrderID",orderID),
            };

            ExecCommand(CancelJobLogsSql.ToString(), SqlParameter);
        }

        public void CancelJobLogsDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [CancelJobLogs] FROM [CancelJobLogs] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [CancelJobLogs].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [CancelJobLogs].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName ");


            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }
        
        #endregion 

        #region OperatorRoles

        public void OperatorRolesInsert(string operatorID, int roleID, string server)
        {
            StringBuilder OperatorRolesSql = new StringBuilder();

            OperatorRolesSql.Append(" INSERT INTO  [OperatorRoles] ");
            OperatorRolesSql.Append(" ([OperatorID] ");
            OperatorRolesSql.Append(" ,[RoleID] ");
            OperatorRolesSql.Append(" ,[Server]) ");
            OperatorRolesSql.Append(" VALUES ");
            OperatorRolesSql.Append(" ( @OperatorID, ");
            OperatorRolesSql.Append("   @RoleID,  ");
            OperatorRolesSql.Append("   @Server  ) ");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
                new System.Data.SqlClient.SqlParameter("@OperatorID",operatorID),
                new System.Data.SqlClient.SqlParameter("@RoleID",roleID),
                new System.Data.SqlClient.SqlParameter("@Server",server),

            };

            ExecCommand(OperatorRolesSql.ToString(), SqlParameter);
        }

        public void OperatorRolesDelete( string server )
        {
            StringBuilder OperatorRolesSql = new StringBuilder();

            OperatorRolesSql.Append(" DELETE FROM  [OperatorRoles] WHERE  [Server] =  @Server  ");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {     
                new System.Data.SqlClient.SqlParameter("@Server",server),

            };

            ExecCommand(OperatorRolesSql.ToString(), SqlParameter);
        }

        #endregion

        #region RoleLevels

        public void RoleLevelsInsert(
           int roleListID,
           int roleID,
           int? parentID,
           string levelName,
           int isLastNode,
           string server)
        {
            StringBuilder RoleLevelSql = new StringBuilder();
            RoleLevelSql.Append(" INSERT INTO [RoleLevels]  ");
            RoleLevelSql.Append("([RoleListID]  ");
            RoleLevelSql.Append(",[RoleID]  ");
            RoleLevelSql.Append(",[ParentID]  ");
            RoleLevelSql.Append(",[LevelName]  ");
            RoleLevelSql.Append(",[IsLastNode]  ");
            RoleLevelSql.Append(",[Server])  ");
            RoleLevelSql.Append("VALUES  ");
            RoleLevelSql.Append("( @RoleListID,   ");
            RoleLevelSql.Append(" @RoleID,   ");
            RoleLevelSql.Append(" @ParentID,   ");
            RoleLevelSql.Append(" @LevelName,  ");
            RoleLevelSql.Append(" @IsLastNode,  ");
            RoleLevelSql.Append(" @Server )  ");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {   new System.Data.SqlClient.SqlParameter("@RoleListID",System.Data.SqlDbType.Int),
                new System.Data.SqlClient.SqlParameter("@RoleID",System.Data.SqlDbType.Int),
                new System.Data.SqlClient.SqlParameter("@ParentID",System.Data.SqlDbType.Int),
                new System.Data.SqlClient.SqlParameter("@LevelName",System.Data.SqlDbType.NVarChar,50),
                new System.Data.SqlClient.SqlParameter("@IsLastNode",System.Data.SqlDbType.Bit),
                new System.Data.SqlClient.SqlParameter("@Server",System.Data.SqlDbType.NVarChar,50)

            };


            SqlParameter[0].Value = roleListID;
            SqlParameter[1].Value = roleID;
            if (parentID == null)
            {
                SqlParameter[2].Value = DBNull.Value;
            }
            else
            {
                SqlParameter[2].Value = parentID;
            }

            SqlParameter[3].Value = levelName;
            SqlParameter[4].Value = isLastNode;
            SqlParameter[5].Value = server;

            ExecCommand(RoleLevelSql.ToString(), SqlParameter);
        }

        public void RoleLevelsDelete( string server)
        {
            StringBuilder RoleLevelSql = new StringBuilder();
            RoleLevelSql.Append(" DELETE FROM [RoleLevels] WHERE [Server] = @Server   ");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {     
                new System.Data.SqlClient.SqlParameter("@Server",server),

            };

            ExecCommand(RoleLevelSql.ToString(), SqlParameter);
        }

        #endregion

        #region FrameResult

        public void FrameResultMasterInsert(
            Guid FrameResultID, 
            Guid ParentID, 
            Guid OrderID,
            int CategoryID, 
            string CategoryName,
          
            int BlockCount,
            Guid FJobID,
            Guid GJobID,
            string FLoginName,
            string GLoginName,

            double FDuration,
            double GDuration,
            DateTime FInputDateTime,
            DateTime GInputDateTime, 
            string FComment ,
            string GComment,
            int X, int Y, int Width, int Height, 
            Guid StaticID,
            int fileSize)
        {
            StringBuilder FrameResultMasterSql = new StringBuilder();

            FrameResultMasterSql.Append(" INSERT INTO  [FrameResultMaster] ");
            FrameResultMasterSql.Append(" ([FrameResultID] ");
            FrameResultMasterSql.Append(" ,[ParentID] ");
            FrameResultMasterSql.Append(" ,[OrderID] ");
            FrameResultMasterSql.Append(" ,[CategoryID] ");
            FrameResultMasterSql.Append(" ,[CategoryName] ");
          
            FrameResultMasterSql.Append(" ,[BlockCount] ");
            FrameResultMasterSql.Append(" ,[FJobID] ");
            FrameResultMasterSql.Append(" ,[GJobID] ");
            FrameResultMasterSql.Append(" ,[FLoginName] ");
            FrameResultMasterSql.Append(" ,[GLoginName] ");
            FrameResultMasterSql.Append(" ,[FDuration] ");
            FrameResultMasterSql.Append(" ,[GDuration] ");
            FrameResultMasterSql.Append(" ,[FInputDateTime] ");
            FrameResultMasterSql.Append(" ,[GInputDateTime] ");
            FrameResultMasterSql.Append(" ,[FComment] ");
            FrameResultMasterSql.Append(" ,[GComment] ");
            FrameResultMasterSql.Append(" ,[X] ");
            FrameResultMasterSql.Append(" ,[Y] ");
            FrameResultMasterSql.Append(" ,[Width] ");
            FrameResultMasterSql.Append(" ,[Height] ");
            FrameResultMasterSql.Append(" ,[StaticID]");
            FrameResultMasterSql.Append(" ,[FileSize]");

            FrameResultMasterSql.Append("     ) ");
            FrameResultMasterSql.Append(" VALUES ");
            FrameResultMasterSql.Append(" ( @FrameResultID ");
            FrameResultMasterSql.Append(" ,@ParentID ");
            FrameResultMasterSql.Append(" ,@OrderID ");
            FrameResultMasterSql.Append(" ,@CategoryID ");
            FrameResultMasterSql.Append(" ,@CategoryName ");
 

            FrameResultMasterSql.Append(" ,@BlockCount ");
            FrameResultMasterSql.Append(" ,@FJobID ");
            FrameResultMasterSql.Append(" ,@GJobID ");
            FrameResultMasterSql.Append(" ,@FLoginName ");
            FrameResultMasterSql.Append(" ,@GLoginName ");
            FrameResultMasterSql.Append(" ,@FDuration ");
            FrameResultMasterSql.Append(" ,@GDuration ");
            FrameResultMasterSql.Append(" ,@FInputDateTime ");
            FrameResultMasterSql.Append(" ,@GInputDateTime ");
            FrameResultMasterSql.Append(" ,@FComment ");
            FrameResultMasterSql.Append(" ,@GComment ");
            FrameResultMasterSql.Append(" ,@X ");
            FrameResultMasterSql.Append(" ,@Y ");
            FrameResultMasterSql.Append(" ,@Width ");
            FrameResultMasterSql.Append(" ,@Height ");
            FrameResultMasterSql.Append(" ,@StaticID");
            FrameResultMasterSql.Append(" ,@FileSize )"); 

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
                new System.Data.SqlClient.SqlParameter("@FrameResultID", FrameResultID),
                new System.Data.SqlClient.SqlParameter("@ParentID",     ParentID),
                new System.Data.SqlClient.SqlParameter("@OrderID",      OrderID),
                new System.Data.SqlClient.SqlParameter("@CategoryID",   CategoryID),
                new System.Data.SqlClient.SqlParameter("@CategoryName", CategoryName),
  
                 new System.Data.SqlClient.SqlParameter("@BlockCount",   BlockCount),
                new System.Data.SqlClient.SqlParameter("@FJobID",       FJobID),
                new System.Data.SqlClient.SqlParameter("@GJobID",       GJobID),
                new System.Data.SqlClient.SqlParameter("@FLoginName",   FLoginName),
                new System.Data.SqlClient.SqlParameter("@GLoginName",   GLoginName),
                new System.Data.SqlClient.SqlParameter("@FDuration" ,   FDuration),
                new System.Data.SqlClient.SqlParameter("@GDuration",    GDuration),                
                new System.Data.SqlClient.SqlParameter("@FInputDateTime",FInputDateTime),
                new System.Data.SqlClient.SqlParameter("@GInputDateTime",GInputDateTime),

                new System.Data.SqlClient.SqlParameter("@FComment",FComment),
                new System.Data.SqlClient.SqlParameter("@GComment",GComment),
                new System.Data.SqlClient.SqlParameter("@X",X),
                new System.Data.SqlClient.SqlParameter("@Y",Y),
                new System.Data.SqlClient.SqlParameter("@Width",Width),
                new System.Data.SqlClient.SqlParameter("@Height",Height),
                new System.Data.SqlClient.SqlParameter("@StaticID",StaticID),
                new System.Data.SqlClient.SqlParameter("@FileSize",fileSize),
            };

            if (FInputDateTime == System.DateTime.MinValue)
                SetEmptyToNull (ref SqlParameter,"@FInputDateTime");

            if (GInputDateTime == System.DateTime.MinValue)
                SetEmptyToNull(ref SqlParameter, "@GInputDateTime") ;

            if (FLoginName == string.Empty)
                SetEmptyToNull(ref SqlParameter, "@FLoginName") ;

            if (GLoginName == string.Empty)
                SetEmptyToNull(ref SqlParameter, "@GLoginName") ;

            //if (FJobID == Guid.Empty)
            //     SetEmptyToNull (ref SqlParameter, "@FJobID") ;

            //if (GJobID == Guid.Empty)
            //     SetEmptyToNull (ref SqlParameter, "@GJobID") ;

            ExecCommand(FrameResultMasterSql.ToString(), SqlParameter);
        }

  

        public void FrameResultDetailInsert(
            Guid orderID,
            Guid frameResultID,
            Guid jobID ,
            string jobClass, string ImageType,
            int X, int Y, int Width, int Height, 
            string result,
            bool isChange,
            Guid StaticID
            )
        {
            StringBuilder FrameResultDetailSql = new StringBuilder();

            FrameResultDetailSql.Append(" INSERT INTO  [FrameResultDetail] ");
            FrameResultDetailSql.Append(" (");
            FrameResultDetailSql.Append("  [OrderID] ");
            FrameResultDetailSql.Append(" ,[FrameResultID] ");
            FrameResultDetailSql.Append(" ,[JobID] ");
            FrameResultDetailSql.Append(" ,[JobClass] ");
            FrameResultDetailSql.Append(" ,[ImageType] ");
             FrameResultDetailSql.Append(" ,[X] ");
            FrameResultDetailSql.Append(" ,[Y] ");
            FrameResultDetailSql.Append(" ,[Width] ");
            FrameResultDetailSql.Append(" ,[Height] ");
            FrameResultDetailSql.Append(" ,[Result] ");
            FrameResultDetailSql.Append(" ,[IsChange] ");
            FrameResultDetailSql.Append(" ,[StaticID]");
            FrameResultDetailSql.Append("     ) ");

            FrameResultDetailSql.Append(" VALUES ( ");
            FrameResultDetailSql.Append("  @OrderID ");
            FrameResultDetailSql.Append(" ,@FrameResultID ");
            FrameResultDetailSql.Append(" ,@JobID ");
            FrameResultDetailSql.Append(" ,@JobClass ");
            FrameResultDetailSql.Append(" ,@ImageType ");
            FrameResultDetailSql.Append(" ,@X ");
            FrameResultDetailSql.Append(" ,@Y ");
            FrameResultDetailSql.Append(" ,@Width ");
            FrameResultDetailSql.Append(" ,@Height ");
            FrameResultDetailSql.Append(" ,@Result ");
            FrameResultDetailSql.Append(" ,@IsChange ");
            FrameResultDetailSql.Append(" ,@StaticID");
            FrameResultDetailSql.Append("     ) ");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {   
                new System.Data.SqlClient.SqlParameter("@OrderID", orderID),
                new System.Data.SqlClient.SqlParameter("@FrameResultID", frameResultID),
                new System.Data.SqlClient.SqlParameter("@JobID",jobID),
                new System.Data.SqlClient.SqlParameter("@JobClass",jobClass),
                new System.Data.SqlClient.SqlParameter("@ImageType", ImageType),
                new System.Data.SqlClient.SqlParameter("@X",X),
                new System.Data.SqlClient.SqlParameter("@Y",Y),
                new System.Data.SqlClient.SqlParameter("@Width",Width),
                new System.Data.SqlClient.SqlParameter("@Height",Height),
                new System.Data.SqlClient.SqlParameter("@Result",result),
                new System.Data.SqlClient.SqlParameter("@IsChange",isChange),
                new System.Data.SqlClient.SqlParameter("@StaticID",StaticID),
            };

            //if (jobID == Guid.Empty)
            //    SetEmptyToNull(ref SqlParameter, "@JobID");

            ExecCommand(FrameResultDetailSql.ToString(), SqlParameter);

        }


        public void FrameResultDelete(Guid OrderID)
        {
            StringBuilder FrameResultSql = new StringBuilder();

            FrameResultSql.Append(" DELETE FROM [FrameResultMaster] WHERE [OrderID] = @OrderID ;");
            FrameResultSql.Append(" DELETE FROM [FrameResultDetail] WHERE [OrderID] = @OrderID ;");

            System.Data.SqlClient.SqlParameter[] SqlParameter;
            SqlParameter = new System.Data.SqlClient.SqlParameter[]
            {    
                new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
            };

            ExecCommand(FrameResultSql.ToString(), SqlParameter);
        }

        public void FrameResultDelete(Guid OrderID, string ServerName)
        {
            StringBuilder orderSql = new StringBuilder();

            orderSql.Append("    DELETE [FrameResultMaster] FROM [FrameResultMaster] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [FrameResultMaster].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [FrameResultMaster].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName; ");

            orderSql.Append("    DELETE [FrameResultDetail] FROM [FrameResultDetail] ");
            orderSql.Append("    INNER JOIN [StaticState] ON [FrameResultDetail].[StaticID] = [StaticState].[StaticID] ");
            orderSql.Append("    WHERE  [FrameResultDetail].[OrderID] = @OrderID AND [StaticState].Memo = @ServerName; ");

            SqlParameter[] SqlParameter = new[]
              {          
                  new System.Data.SqlClient.SqlParameter("@OrderID",OrderID),
                  new System.Data.SqlClient.SqlParameter("@ServerName",ServerName),
              };

            ExecCommand(orderSql.ToString(), SqlParameter);
        }
        #endregion FrameResult

        #region 私有方法

        private   void ExecCommand(String sql)
        {

            try
            {
                
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {
                    conn.Open();

                    int timeout =0 ;
                    int.TryParse(Config.Setting.SettingInstance.DecompositionDBTimeOut, out timeout);

                    if (timeout > 0)
                    {
                        SqlHelper.TimeOut = timeout;
                    }

                    SqlHelper.ExecuteNonQuery(conn, System.Data.CommandType.Text, sql);

                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();


                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw (new Exception(ex.Message));
            }
        }

        private void ExecCommand(String sql, System.Data.SqlClient.SqlParameter[] SqlParameter)
        {
            try
            {
                

                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectString))
                {
                    conn.Open();

                    int timeout = 0;
                    int.TryParse(Config.Setting.SettingInstance.DecompositionDBTimeOut, out timeout);

                    if (timeout > 0)
                    {
                        SqlHelper.TimeOut = timeout;
                    }

                    SqlHelper.ExecuteNonQuery(conn, System.Data.CommandType.Text, sql,SqlParameter);

                    if (conn.State == System.Data.ConnectionState.Open)
                        conn.Close();


                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw (new Exception(ex.Message));
            }
        }

        private void SetEmptyToNull(ref System.Data.SqlClient.SqlParameter[] sqlParameter, string paramName)
        {
            sqlParameter.Single(t => t.ParameterName == paramName).Value = DBNull.Value;
        }
        #endregion

    }
  }
 
